package com.example.demo.controller;

import com.example.demo.demos.web.Constant.CommonConstant;
import com.example.demo.entity.UserInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class IndexCotroller {
    @RequestMapping("/login")
    @ResponseBody
    public String login(String userName,String passWord){
        if (!CommonConstant.name_wordMap.containsKey(userName)) {
            System.out.println("用户名不存在");
            return "用户名不存在";
        }else {
            System.out.println("用户名存在进行密码校验");
            String map_password = CommonConstant.name_wordMap.get(userName);
            if (passWord.equals(map_password)){
                return "登录成功";
            }else {
                return "登录失败，密码不对";
            }
        }
    }

    @RequestMapping("/resgin")
    @ResponseBody
    public String resgin(String userName,String passWord){
        System.out.println("访问到前端的登录请求");
//       新建一个用户
        UserInfo user=new UserInfo();
        user.setUserName(userName);
        user.setPassWord(passWord);
//        把用户存入数据库
        CommonConstant.name_wordMap.put(userName,passWord);
        return "注册成功";
    }
}
